
import { Config } from 'config.js'

class Base {
  constructor() {
    this.baseRequestUrl = Config.baseUrl;
  }

  request(params) {
    if ( !params.type) {
      params.type = 'GET';
    }

    wx.request({
      url: this.baseRequestUrl + params.url,
      method: params.type,
      data : params.data,
      header : {
        "content-type" : 'application/json',
        "token" : wx.getStorageSync('token')
      },
      success : function(res) {
        params.sCallBack && params.sCallBack(res.data);
      },

      fail : function(err) {
        console.log(err);
      }
    })
  }

  getDataset(event, key) {
    return event.currentTarget.dataset[key];
  }
}

export { Base }